<template>
  <el-row>
    <el-col :span="24">
      <el-card class="search-form">
        <el-form ref="searchForm" class="el-form-col" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderNo" style="position: relative">
                <el-input v-model="search.orderNo" type="textarea" :rows="4" clearable placeholder="关联订单号  (支持多单查询，用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="inputWarehouseNo" style="position: relative">
                <el-input v-model="search.inputWarehouseNo" type="textarea" :rows="4" clearable placeholder="入库单号  (支持多单查询，用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consigneName">
                <el-input v-model="search.consigneName" placeholder="客户姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6" class="hidden-lg-only hidden-xl-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="info" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consignePhone">
                <el-input v-model="search.consignePhone" placeholder="客户电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="cargoOwner">
                <el-input v-model="search.cargoOwner" placeholder="商家名称"></el-input>
              </el-form-item></el-col>
            <el-col :lg="4" :md="6" class="hidden-md-only hidden-sm-only">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="8">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button type="info" plain @click="isOpen = !isOpen">{{ isOpen ? '收起' : '展开' }}</el-button>
                  </el-col>
                  <el-col :span="8">
                    <el-button @click="resetFields" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderType">
                <el-select v-model="search.orderType" placeholder="关联订单类型">
                  <el-option v-for="item in followTypeArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="inputTypeCode">
                <el-select clearable v-model="search.inputTypeCode" placeholder="仓储类型">
                <!--<el-select clearable v-model="search.warehouse" placeholder="请选择入库仓">-->
                  <el-option v-for="item in tempArr"
                             :key="item.value"
                             :label="item.text"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="foundStart">
                <el-date-picker type="date"
                                placeholder="下单开始时间"
                                v-model="search.foundStart"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="foundEnd">
                <el-date-picker type="date"
                                placeholder="下单结束时间"
                                v-model="search.foundEnd"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <div v-show="isOpen">
              <el-col :lg="4" :md="6">
                <el-form-item prop="orderState">
                  <el-select clearable v-model="search.orderState" placeholder="入库状态">
                    <el-option
                      v-for="item in inputWarehouseArr"
                      :key="item.value"
                      :label="item.text"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </div>
            <!--<el-form-item prop="foundUserName">-->
              <!--<el-input v-model="search.foundUserName" placeholder="录单员"></el-input>-->
            <!--</el-form-item>-->

          </el-row>

        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-warehouse-order/recordOrder/inputWarehouseList"
        :tabs="tabs"
        :columns="columns">
        <template slot="preColumn">
          <el-table-column prop="orderNo" fixed="left" width="170px" align="center" label="关联单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="show(scope.row)">{{ scope.row.orderNo }}</a>
            </template>
          </el-table-column>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="show(scope.row)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>
<script>
import {getAllWarehouse, getInputWarehouse, getSubDictListOfParentCode} from '@/utils/selectOptions'
import {filterDataBaseDictionary, unixTimestampFilter} from '@/filters'
import {copy} from '@/utils'
// import {copy, dotData, confirm} from '@/utils'
export default {
  name: 'warehousingOrderIndex',
  data() {
    return {
      isOpen: false,
      visible: false,
      searchLoading: false,
      search: {
        orderNo: '',
        inputTypeCode: '',
        inputWarehouseNo: '',
        orderType: '',
        warehouse: '',
        foundUserName: '',
        cargoOwner: '',
        orderState: '',
        foundStart: '',
        foundEnd: '',
        consigneName: '',
        consignePhone: ''
      },
      warehouseIdArr: [], // 入库仓
      inputWarehouseArr: [], // 入库状态
      tempArr: [], // 仓储类型
      followTypeArr: [],
      tabs: [],
      columns: [
        {
          label: '入库单号',
          width: '155px',
          data: 'inputWarehouseNo'
        },
        {
          label: '客户姓名',
          data: 'consigneName',
          width: '120px'
        },
        {
          label: '客户电话',
          data: 'consignePhone',
          width: '150px'
        },
        {
          label: '关联订单类型',
          data: 'orderType',
          width: '120px',
          render(data, full) {
            return filterDataBaseDictionary(data)
          }
        },
        {
          label: '入库仓',
          data: 'warehouse',
          width: '100px',
          render(data, full) {
            return filterDataBaseDictionary(data)
          }
        },
        {
          label: '仓储类型',
          data: 'inputTypeCode',
          width: '100px',
          render(data, full) {
            return filterDataBaseDictionary(data)
          }
        },
        {
          label: '商家名称',
          data: 'cargoOwner'
        },
        {
          label: '总体积',
          width: '80px',
          data: 'totalVolume'
        },
        {
          label: '总包件',
          width: '80px',
          data: 'totalPackage'
        },
        {
          label: '总重量',
          width: '80px',
          data: 'totalWeight'
        },
        { label: '操作人', data: 'founderUserName' },
        {
          label: '到件时间',
          width: '155px',
          data: 'foundDate',
          render(data, full) {
            return unixTimestampFilter(data)
          }
        },
        { label: '入库状态',
          width: '80px',
          data: 'orderState',
          render(data, full) {
            return filterDataBaseDictionary(data)
          }
        }
      ]
    }
  },
  created() {
    // 仓储类型：通用字典接口查
    getSubDictListOfParentCode('CARGOSOURCETYPE').then(arr => {
      if (Array.isArray(arr)) {
        this.tempArr = arr
      }
    })
    // 入库仓
    getAllWarehouse().then(arr => {
      this.warehouseIdArr = arr
    })
    // 入库状态
    getInputWarehouse().then(arr => {
      this.inputWarehouseArr = arr
      console.log('inputWarehouseArr', this.inputWarehouseArr)
    })
    // 关联订单类型：通用字典接口查
    getSubDictListOfParentCode('STORAGEORDERTYPE').then(arr => {
      if (Array.isArray(arr)) {
        this.followTypeArr = arr
      }
    })
  },
  methods: {
    // 搜索
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    // 重置表单
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
    },
    // 表格刷新
    refresh() {
      this.searchFunc(this.search)
    },
    // 跳转详情
    show(data) {
      this.$router.push({path: '/ss-oms/enterWarehouse/warehousing-order/show/' + data.id})
    }
  }
}
</script>
